package org.example.controller.usercontroller;

import lombok.extern.slf4j.Slf4j;
import org.example.entity.Course;
import org.example.service.CourseService;
import org.example.utils.Result;
import org.example.vo.CourseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用来管理课程
 */
@RestController
@RequestMapping("/user/course")
@Slf4j
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 创建课程
     */
    @PostMapping("/creatcourse")
    public Result createCourse(@RequestBody Course course) {
        log.info("创建课程:{}", course);
        Boolean result=courseService.createCourse(course);
        if (result){
            return Result.success("课程创建成功");
        }
        return Result.error("课程创建失败");
    }
    /**
     * 获取所有课程
     * TODO后续可能要添加分页查询
     */
    @GetMapping("/getcourse")
    public Result<List<Course>> getAllCourse() {
        log.info("获取所有课程");
        List<Course> course = courseService.getAllCourse();
        if (course != null) {
            return Result.success(course);
        }
        return Result.error("课程不存在");
    }
    /**
     * 获取符合条件的课程
     */
    @GetMapping("/getcoursebycondition")
    public Result<List<Course>> getCourseByCondition(@RequestBody CourseVo courseVo) {
        log.info("获取符合条件的课程:{}", courseVo);
        List<Course> course = courseService.getCourseByCondition(courseVo);
        return Result.success(course);
    }
    /**
     * 修改课程信息
     * 用户可以在这里添加课程评价
     */

    @PutMapping("/updatecourseinfo")
    public Result updateCourseInfo(@RequestBody Course course) {
        log.info("完善课程详情:{}", course);
        Boolean result=courseService.updateCourseInfo(course);
        if (result){
            return Result.success("操作成功");
        }
        return Result.error("操作失败");
    }
}
